#include <app\states\statesFactory.h>
#include <app\states\sessionState.h>

statesFactory *statesFactory::_instance = NULL;

statesFactory &
statesFactory::instance() {
  if (!_instance) {
    _instance = new statesFactory();
  }

  return *_instance;
};

statesFactory::statesFactory() {

}

bool
statesFactory::registerState(unsigned int stateId, createStateCallback createFn) {

  if (states.find(stateId) == states.end()) {
    states.insert(std::pair<unsigned int, createStateCallback>(stateId, createFn));
  }
  return true;
}

bool
statesFactory::unregisterState(unsigned int stateId) { 
  istates = states.find(stateId);
  if (istates != states.end()) {
    states.erase(istates);
    return true;
  }

  return false;
}

sessionState* 
statesFactory::createState(unsigned int stateId) {

  istates = states.find(stateId);
  if (istates != states.end()) {
    return istates->second();
  }

  return NULL;
}